//
// Created by Administrator on 2023/11/15.
//

#include "iostream"

using namespace std;

const int N = 1e5 + 10;
int A[N];
int n, m;


int find(int i) {
    // 如果 不是根 则继续找 （递归版+路径压缩）
    if (A[i] == i)return i;
    A[i] = find(A[i]);

    //循环版 没有路径压缩
    // while(i!=A[i])i=A[i];
    //return i;
}

// 将i的并查集树连入j上
void merge(int i, int j) {
    A[find(i)] = find(j);
}


int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        A[i] = i;
    char x;
    int i, j;


    while (m--) {
        cin >> x >> i >> j;
        if (x == 'M')
            merge(i, j);
        else if (x == 'Q') {
            if (find(i) == find(j)) cout << "Yes" << endl;
            else cout << "No" << endl;
        }

    }
}